using B.S.Data.MES.API.Applications.BaseData.Command.CustomerCommand;
using B.S.Domain.基础数据.客户管理;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.CustomerCommandHandlers
{
    public class DeleCustomerCommandHandlers : IRequestHandler<DeleCustomerCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<client> customerRepository;

        public DeleCustomerCommandHandlers(IBaseRepository<client> customerRepository)
        {
            this.customerRepository = customerRepository;
        }

        public async Task<APIRequst<int>> Handle(DeleCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = customerRepository.GetAll().FirstOrDefault(x => x.CustomerID == request.CustomerID);
            customer.isDel = true;
            await customerRepository.Update(customer);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };

        }
    }
}